package com.shenghua.controller;

import com.alibaba.fastjson.JSON;
import com.shenghua.dao.page.Page;
import com.shenghua.utils.beans.Dto;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;

/**
 * Created by Administrator on 2018/12/30.
 */
public abstract class BaseController<T> {
    private static Logger logger = LoggerFactory.getLogger(BaseController.class);

    protected Page getRequestPageInfo(Map<String, Object> params) {
        if (null == params || params.size() == 0) {
            logger.debug("[BaseController] getRequestPageRollInfo request params is null");
            return new Page(0, 20);
        }
        Integer start = Integer.parseInt(params.get("page").toString());
        Integer length = Integer.parseInt(params.get("rows").toString());
        return new Page(start, length);
    }

    protected String respJson(T data) {
        Dto<T> dto = new Dto<>();
        dto.setData(data);
        return JSON.toJSONString(dto);
    }
}
